home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / CMD_EX.BAS < prev    next >
BASIC Source File  |  1988-09-17  |  2KB  |  57 lines

  1. '
  2. ' *** CMD_EX.BAS -- COMMAND$ function programming example
  3. '
  4. ' Default variable type is integer in this module.
  5. DEFINT A-Z
  6.  
  7. ' Declare the Comline subprogram, as well as the number and
  8. ' type of its parameters.
  9. DECLARE SUB Comline(N, A$(),Max)
  10.  
  11. DIM A$(1 TO 15)
  12. ' Get what was typed on the command line.
  13. CALL Comline(N,A$(),10)
  14. ' Print out each part of the command line.
  15. PRINT "Number of arguments = ";N
  16. PRINT "Arguments are: "
  17. FOR I=1 TO N : PRINT A$(I) : NEXT I
  18.  
  19. ' Subroutine to get command line and split into arguments.
  20. ' Parameters:  NumArgs : Number of command line args found.
  21. '              Args$() : Array in which to return arguments.
  22. '              MaxArgs : Maximum number of arguments array
  23. '                        can return.
  24.  
  25. SUB Comline(NumArgs,Args$(1),MaxArgs) STATIC
  26. CONST TRUE=-1, FALSE=0
  27.  
  28.    NumArgs=0 : In=FALSE
  29. ' Get the command line using the COMMAND$ function.
  30.    Cl$=COMMAND$
  31.    L=LEN(Cl$)
  32. ' Go through the command line a character at a time.
  33.    FOR I=1 TO L
  34.       C$=MID$(Cl$,I,1)
  35.     'Test for character being a blank or a tab.
  36.       IF (C$<>" " AND C$<>CHR$(9)) THEN
  37.     ' Neither blank nor tab.
  38.     ' Test to see if you're already
  39.     ' inside an argument.
  40.          IF NOT In THEN
  41.       ' You've found the start of a new argument.
  42.       ' Test for too many arguments.
  43.             IF NumArgs=MaxArgs THEN EXIT FOR
  44.             NumArgs=NumArgs+1
  45.             In=TRUE
  46.          END IF
  47.      ' Add the character to the current argument.
  48.          Args$(NumArgs)=Args$(NumArgs)+C$
  49.       ELSE
  50.    ' Found a blank or a tab.
  51.    ' Set "Not in an argument" flag to FALSE.
  52.          In=FALSE
  53.       END IF
  54.    NEXT I
  55.  
  56. END SUB
  57.